package com.htudata.core.util;

public class IpUtils {
  public static long ip2Long(String ipStr) {
    String[] ip = ipStr.split("\\.");
    return (Long.valueOf(ip[0]).longValue() << 24L) + (Long.valueOf(ip[1]).longValue() << 16L) + (Long.valueOf(ip[2]).longValue() << 8L) + 
      Long.valueOf(ip[3]).longValue();
  }
  
  public static String long2Ip(long ipLong) {
    StringBuilder ip = new StringBuilder();
    ip.append(ipLong >>> 24L).append(".");
    ip.append(ipLong >>> 16L & 0xFFL).append(".");
    ip.append(ipLong >>> 8L & 0xFFL).append(".");
    ip.append(ipLong & 0xFFL);
    return ip.toString();
  }
}
